package com.ervanalb.cellradio.client;

/**
 * This class is a wrapper class which attaches an optional message to any type.
 * It is useful when a method has the possibility of several failure modes.
 * Under normal operation, the method will return an Informational with only the
 * result set, and the message null. Under a fault condition, the method will
 * return an Informational with only the message set (describing the failure),
 * and the result null. If success / failure is the only return type, an
 * Informational<Boolean> should be used.
 * 
 * @author eric
 * @param <E>
 *            the wrapped type.
 */
public class Informational<E> {
	public E result;
	public String message;

	public Informational(String message) {
		this.result = null;
		this.message = message;
	}

	public Informational(E result) {
		this.result = result;
		this.message = null;
	}

	public Informational(E result, String message) {
		this.result = result;
		this.message = message;
	}

	public String toString() {
		if (message != null)
			return message;
		else
			return result.toString();
	}
}
